package com.eaero.config;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.lang.Console;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Author zb
 * @Date 2024/9/27 9:34
 */

@Configuration
public class FeignConfig {
    @Bean
    public RequestInterceptor headerInterceptor() {
        return new HeaderInterceptor();
    }

    public static class HeaderInterceptor implements RequestInterceptor {

        @Override
        public void apply(RequestTemplate template) {
            String jsonBody = template.requestBody().asString();
            try {
                template.body(Base64.encode(jsonBody.getBytes()));
            } catch (Exception e) {
                Console.error("feign请求入参加密失败");
            }

            template.header("Authorization","accessToken");
        }
    }
}
